class MyWebSocket {
    static ws = undefined;
    content = undefined;

    link(id) {
        if ('WebSocket' in window) {
            this.ws = new WebSocket('ws://localhost:8002/websocket/' + id)
            this.init();
        } else {
            alert("浏览器不支持，建议使用FireFox、Chrome")
        }
    }

    init() {
        window.onbeforeunload = this.ws.onclose
        this.ws.onclose = this.close;
        this.ws.onerror = this.error;
    }

    close() {
        document.write("链接关闭")
    }

    error(event) {
        document.writeln("错误")
        document.writeln(JSON.stringify(event))
    }
}